/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package embuzzled.ui;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
 *
 * @author Satyajeet
 */
public class PlayerController {


    public ArrayList<String> getPlayerList()
    {
        ArrayList<String> plist = new ArrayList<String>();

            try{
            // Open the file that is the first
            // command line parameter
            FileInputStream fstream = new FileInputStream("Game.playerlist");
            // Get the object of DataInputStream
            DataInputStream in = new DataInputStream(fstream);
                BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String strLine;
            //Read File Line By Line
            while ((strLine = br.readLine()) != null)   {
              // Print the content on the console
              //System.out.println (strLine);
              plist.add(strLine);
            }
            //Close the input stream
            in.close();
            }catch (Exception e){//Catch exception if any
              System.err.println("Error: " + e.getMessage());
            }

        return plist;
    }

    public GridSolution makePlay(Grid grid, String player) throws ClassNotFoundException, InstantiationException, IllegalAccessException
    {
        Class<Player> pc_object = (Class<Player>)Class.forName(player);
        Player myplayer = (Player)pc_object.newInstance();
        GridSolution gs = myplayer.move(grid);
        return gs;

    }


}
